import 'package:flutter/material.dart';

class MainPageBottomBar {
  final double _iconSize = 96;
  bool _isChatSelected = true;
  bool _isOrganizationSelected = false;
  bool _isMySelected = false;
  late StateSetter _setChatState;
  late StateSetter _setOrganizationState;
  late StateSetter _setMyState;

  final ValueChanged<int> onButtonPressed;

  MainPageBottomBar({required this.onButtonPressed});

  Widget? createBottomBar() {
    return Container(
      height: 60,
      decoration: const BoxDecoration(
        image: DecorationImage(image: AssetImage("assets/images/xxhdpi/bottom_navigation_bar_bg.png", package: "resource"), fit: BoxFit.none),
      ),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceAround,
        children: <Widget>[
          StatefulBuilder(builder: (BuildContext context, void Function(void Function()) setState) {
            _setChatState = setState;
            return Stack(children: <Widget>[
              IconButton(
                onPressed: () {
                  _isChatSelected = true;
                  _isOrganizationSelected = false;
                  _isMySelected = false;
                  _setChatState(() {});
                  _setOrganizationState(() {});
                  _setMyState(() {});
                  onButtonPressed(0);
                },
                splashColor: Colors.transparent,
                highlightColor: Colors.transparent,
                isSelected: _isChatSelected,
                iconSize: _iconSize,
                icon: const Image(
                  gaplessPlayback: true,
                  image: AssetImage("assets/images/xxhdpi/chat.png", package: "resource"),
                ),
                selectedIcon: const Image(
                  gaplessPlayback: true,
                  image: AssetImage("assets/images/xxhdpi/chat_select.png", package: "resource"),
                ),
              ),
              Positioned(right: 5, top: 10, child: Badge.count(backgroundColor: Colors.red, count: 10))
            ]);
          }),
          StatefulBuilder(builder: (BuildContext context, void Function(void Function()) setState) {
            _setOrganizationState = setState;
            return IconButton(
              onPressed: () {
                _isChatSelected = false;
                _isOrganizationSelected = true;
                _isMySelected = false;
                _setChatState(() {});
                _setOrganizationState(() {});
                _setMyState(() {});
                onButtonPressed(1);
              },
              splashColor: Colors.transparent,
              highlightColor: Colors.transparent,
              isSelected: _isOrganizationSelected,
              iconSize: _iconSize,
              icon: const Image(
                gaplessPlayback: true,
                image: AssetImage("assets/images/xxhdpi/organization.png", package: "resource"),
              ),
              selectedIcon: const Image(
                gaplessPlayback: true,
                image: AssetImage("assets/images/xxhdpi/organization_select.png", package: "resource"),
              ),
            );
          }),
          StatefulBuilder(builder: (BuildContext context, void Function(void Function()) setState) {
            _setMyState = setState;
            return IconButton(
              onPressed: () {
                _isChatSelected = false;
                _isOrganizationSelected = false;
                _isMySelected = true;
                _setChatState(() {});
                _setOrganizationState(() {});
                _setMyState(() {});
                onButtonPressed(2);
              },
              splashColor: Colors.transparent,
              highlightColor: Colors.transparent,
              isSelected: _isMySelected,
              iconSize: _iconSize,
              icon: const Image(
                gaplessPlayback: true,
                image: AssetImage("assets/images/xxhdpi/my.png", package: "resource"),
              ),
              selectedIcon: const Image(
                gaplessPlayback: true,
                image: AssetImage("assets/images/xxhdpi/my_select.png", package: "resource"),
              ),
            );
          }),
        ],
      ),
    );
  }
}
